import numpy as np
import torch
from torchvision import transforms
from PIL import Image
import sys

def image_resize(resize_size=256, crop_size=224):
    
    return transforms.Compose([
        # transforms.ToPILImage(),
        transforms.Resize(resize_size),
        transforms.RandomResizedCrop(crop_size),
        # transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
    ])
model_dir = '/home/lss/HSP-master/ml/64bit_5e_0.8612_resnet50.pkl'
model = torch.load(model_dir, map_location=torch.device('cpu'))
sys.path.insert(0, '/home/lss/HSP-master/ml')
model.batch = 1
model = model.module
image = Image.open('/home/lss/HSP-master/ml/n03196217_10139.JPEG')
print(image)
input = image_resize(resize_size=256, crop_size=224)(image).float()
model.eval()
batch_size = 64
input = torch.tensor(input.repeat(batch_size,1,1,1),requires_grad=False)
y = model(input).detach().cpu().numpy()[0]
T = 0
y[y >= T] = 1
y[y < T] = 0
print(y)